﻿@model DefeatEpidemic.Models.Community

<link href="~/lib/layui-extend/city-picker/citypicker.css" rel="stylesheet" />
<script src="~/lib/layui-extend/city-picker/citypicker.data.js"></script>
<div class="layui-row">
    <span class="layui-breadcrumb">
        <a href="~/home/index">首页</a>
        <a href="~/communities/Index">社区管理</a>
        <a>
            <cite>编辑修改</cite>
        </a>
    </span>
    <a class="layui-btn layui-btn-xs" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh-1" style="line-height:25px;font-size: 10px"></i>
    </a>
</div>
<hr />
<div class="layui-row">
    <form asp-action="Edit" class="layui-form">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <input type="hidden" asp-for="id" />
        <div class="layui-form-item">
            <label asp-for="name" class="layui-form-label"></label>
            <div class="layui-input-block">
                <input asp-for="name" class="layui-input" placeholder="请输入社区名" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width_auto text-r" style="margin-top:2px">省市区(县)：</label>
            <div class="layui-input-inline" style="width:400px">
                <input type="text" autocomplete="on" class="layui-input" id="city-picker" name="city-picker" readonly="readonly" data-toggle="city-picker" placeholder="请选择">
            </div>
        </div>
        <input type="hidden" id="pca" value="@Model.province/@Model.city/@Model.area" />
        <div class="layui-form-item">
            <label asp-for="detail" class="layui-form-label"></label>
            <div class="layui-input-block">
                <input asp-for="detail" class="layui-input" placeholder="请输入具体地址" lay-verify="required" />
            </div>
        </div>
        <div class="layui-form-item" style="padding-left:30px">
            <a class="layui-btn" href="javascript:;" lay-submit lay-filter="save">保存</a>
            <a asp-action="Index" class="layui-btn layui-btn-primary">返回列表</a>
        </div>
    </form>
    <hr />
    <div class="layui-form-item">
        <a class="layui-btn layui-btn-normal" href="javascript:;" id="btn_add">添加物管成员</a>
    </div>
    <table class="layui-table" id="table"></table>
</div>


<script type="text/html" class="layer_notice" style="display:none" id="div_add_member">
    <br />
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input id="m_name" name="m_name" class="layui-input" placeholder="请输入姓名" lay-verify="required" style="width:90%" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">身份证</label>
            <div class="layui-input-block">
                <input id="m_idcard" name="m_idcard" class="layui-input" placeholder="请输入身份证号" lay-verify="required" style="width:90%" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-block">
                <input id="m_address" name="m_address" class="layui-input" placeholder="请输入住址" lay-verify="required" style="width:90%" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input id="m_mobile" name="m_mobile" class="layui-input" placeholder="请输入手机号码" lay-verify="required" style="width:90%" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input id="m_remark" name="m_remark" class="layui-input" placeholder="请输入备注信息" lay-verify="required" style="width:90%" />
            </div>
        </div>
        <div class="layui-form-item" style="padding-left:30px">
            <a class="layui-btn" href="javascript:;" lay-submit lay-filter="m_save">保存</a>
        </div>
    </form>

</script>

<script type="text/html" id="operationTpl">
    <a onclick="del('{{ d.id }}')" class="layui-btn layui-btn-danger">删除</a>
</script>
<script type="text/html" id="checkboxTpl">
    <input type="checkbox" name="id" lay-skin="primary" lay-filter="ck_item" id="{{ d.id }}" class="ck">
</script>
<script>
    var token = $('@Html.AntiForgeryToken()').val();
    var form = layui.form;
    layui.config({
        base: '/lib/layui-extend/city-picker/'
    }).use(['jquery','citypicker'], function () {
        var $ = layui.$
            , cityPicker = layui.citypicker;

        var currentPicker = new cityPicker("#city-picker", {
            provincename: "provinceId",
            cityname: "cityId",
            districtname: "districtId",
            level: 'districtId',// 级别
        });
        var current_pca = $("#pca").val();
        currentPicker.setValue(current_pca);

        form.on('submit(save)', function (data) {
            var pca = currentPicker.getVal().split('/');
            var province = pca[0];
            var city = pca[1];
            var area = pca[2];
            var jsonData = {
                "id": data.field.id,
                "name": data.field.name,
                "province": province,
                "city": city,
                "area": area,
                "detail": data.field.detail,
                "__RequestVerificationToken": token
            };
            var params = {
                'url': '@Url.Action("Edit")',
                'type': 'post',
                'data': jsonData,
                'showMsg': true,
                'refresh': true,
            };
            sendAjax(params);
        });
    })

    var community_id = $("#id").val();
    var params = {
        url: '@Url.Action("GetManagers")',
        elem: '#table',
        where: { 'community_id': community_id },
        size: 'lg',
        page: true,
        cols: [ //表头
            //, { field: 'id', title: 'ID', sort: true, fixed: 'left' }
            { field: 'name', title: '姓名' }
            , { field: 'idcard', title: '身份证号' }
            , { field: 'mobile', title: '联系方式' }
            , { field: 'address', title: '地址' }
            , { field: 'remark', title: '备注' }
            , { title: '操作', templet: '#operationTpl' }
        ],
        height:630
    }
    getTable(params);

    $("#btn_add").click(function () {
        openDiv('添加管理人员', 'div_add_member', '50%', '45%', true);
        form.on('submit(m_save)', function (data) {
            data.field.community_id = "@Model.id";
            data.field.__RequestVerificationToken = token;
            var params = {
                'url': '@Url.Action("AddManager")',
                'type': 'post',
                'data': data.field,
                'showMsg': true,
                'refresh': true,
            };
            sendAjax(params);
        });
    })

    function del(member_id) {
        UpdateItem("@Url.Action("DeleteManager")", { "member_id": member_id, "community_id": "@Model.id","__RequestVerificationToken": token }, "确定要删除该物管人员吗");
    }

</script>
